package com.zf.shuashua.ui.popup;

import android.app.Activity;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.CenterPopupView;
import com.zf.shuashua.R;
import com.zf.shuashua.api.Store;
import com.zf.shuashua.manager.AdAutoTouchManager;

/**
 * 提升活跃度弹框
 */
public class PromoteActivePopup extends CenterPopupView {

    private TextView btnTitle;
    private FrameLayout advert_container;
    private View view;

    public PromoteActivePopup(@NonNull Activity context) {
        super(context);
    }

    public void addAdvertView(View view) {
        this.view = view;
        advert_container.removeAllViews();
        advert_container.addView(view);
        btnTitle.setVisibility(VISIBLE);
    }

    public void loadAdvertFail() {
        advert_container.setVisibility(GONE);
        btnTitle.setVisibility(VISIBLE);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.promote_active_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        setupView();
    }

    private void setupView() {
        btnTitle = findViewById(R.id.btTitle);
        TextView tvContent = findViewById(R.id.tv_content);
        tvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
        advert_container = findViewById(R.id.advert_container);
        btnTitle.setOnClickListener(v -> {
            if (!AdAutoTouchManager.getInstance().randomAutoClickAd(view)) {
                dismiss();
            }
        });

//        if (Store.getInstance().getTP_AD()) {
//            findViewById(R.id.flCancel).setOnClickListener(v -> {
//                dismiss();
//            });
//        } else {
//            btnTitle.setOnClickListener(v -> {
//                dismiss();
//
//            });
//        }
    }

}

